package com.itbaizhan.shopping_common.utils;

import java.util.Random;

/**
 * @author spf
 * @date 2024/1/10
 * @time 12:34
 */

// 生成随机数工具类
public class RandomUtil {
    /**
     * 生成手机验证码
     *
     * @param digit 位数
     * @return 执行结果(验证码)
     */
    public static String buildCheckCode(int digit) {
        String str = "0123456789";
        StringBuilder builder = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < digit; i++) {
            char ch = str.charAt(random.nextInt(str.length()));
            builder.append(ch);
        }
        return builder.toString();
    }
}
